import { CommentResult, CommentsPageQuery } from '@/types/comments';
import { PageParams, PageResult } from '@/types/common';
import { OrderDetailInfo, OrderResult, OrderStatistics } from '@/types/order';
import request from "@/utils/request";
/**
 * 订单分页查询
 */
type OrderPageParams = PageParams & {
  beginTime?: string
  endTime?: string
  businessId?: number
  number?: string
  phone?: string
  status?: number
}
export const getOrderPageAPI = (params: OrderPageParams) => {
  return request<PageResult<OrderResult[]>>({
    method: 'GET',
    url: '/business/order/conditionSearch',
    params: { ...params }
  })
}
/**
 * 各个状态的订单数量统计
 * @returns 
 */
export const getOrderStatisticsAPI = (params: { businessId?: number }) => {
  return request<OrderStatistics>({
    method: 'GET',
    url: '/business/order/statistics',
    params: { ...params }
  })
}
/**
 * 接单
 * @param params 
 * @returns 
 */
export const confirmOrderAPI = (id: number) => {
  return request({
    method: 'PUT',
    url: `/business/order/confirm/${id}`,
  })
}
/**
 * 派送订单
 * @param params 
 * @returns 
 */
export const deliveryOrderAPI = (id: number) => {
  return request({
    method: 'PUT',
    url: `/business/order/delivery/${id}`,
  })
}
/**
 * 完成订单
 * @param params 
 * @returns 
 */
export const completeOrderAPI = (id: number) => {
  return request({
    method: 'PUT',
    url: `/business/order/complete/${id}`,
  })
}
/**
 * 取消订单
 */
interface CancelParams {
  cancelReason: string
  id: number
}
export const cancelOrderAPI = (params: CancelParams) => {
  return request({
    method: 'PUT',
    url: '/business/order/cancel',
    data: params
  })
}
/**
 * 拒绝订单
 */
interface RejectParams {
  rejectionReason: string
  id: number
}
export const rejectOrderAPI = (params: RejectParams) => {
  return request({
    method: 'PUT',
    url: '/business/order/rejection',
    data: params
  })
}
/**
 * 查询订单详情
 * @param id 
 * @returns 
 */
export const getOrderDetailAPI = (id: number) => {
  return request<OrderDetailInfo>({
    method: 'GET',
    url: `/business/order/details/${id}`
  })
}
/**
 * 评论分页查询
 * @returns
 */
export const getCommentListAPI = (data: CommentsPageQuery) => {
  return request<CommentResult>({
    method: 'POST',
    url: '/business/comments/pageQuery',
    data,
  })
}